package com.smalls.redshoes.ui.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.SeekBar;

import com.smalls.newvideotwo.util.LogUtil;
import com.smalls.newvideotwo.utils.Constant;
import com.smalls.redshoes.ui.fragment.LivePlayFragment;

import org.apache.http.HttpStatus;

@SuppressLint("AppCompatCustomView")
public class AccelerationSeekBar extends SeekBar {
    private static String TAG = Constant.baddcoolio2tag?Constant.TAGPREFIXSTR + AccelerationSeekBar.class.getSimpleName():AccelerationSeekBar.class.getSimpleName();
    private int c;
    private int d;
    private int increment;
    private int mDuration;
    private int maxMultiple;

    public AccelerationSeekBar(Context context) {
        this(context, null);
    }

    public AccelerationSeekBar(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AccelerationSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.increment = 1;
        this.maxMultiple = 10;
        this.c = 3;
        this.d = 2;
        this.mDuration = 1;
    }

    private void setIncrement() {
        this.c--;
        if (this.c <= 0) {
            if (this.d <= this.maxMultiple && this.increment != 0) {
                setKeyProgressIncrement(this.d * this.increment);
                this.d++;
            }
            this.c = 3;
        }
    }

    public synchronized void setProgress(int progress) {
        LogUtil.d(this.TAG, "setProgress");
        super.setProgress(progress);
    }

    protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
        LogUtil.d(this.TAG, "onFocusChanged=" + gainFocus);
        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    }

    public void setMax(int max) {
        super.setMax(max);
        this.increment = max / HttpStatus.SC_INTERNAL_SERVER_ERROR;
        setKeyProgressIncrement(this.increment);
    }

    public boolean onTouchEvent(MotionEvent event) {
        return super.onTouchEvent(event);
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        LogUtil.d(this.TAG, "onKeyDown");
        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
            case KeyEvent.KEYCODE_DPAD_RIGHT /*22*/:
                setIncrement();
                break;
        }
        return super.onKeyDown(keyCode, event);
    }

    public boolean onKeyUp(int keyCode, KeyEvent event) {
        LogUtil.d(this.TAG, "onKeyUp");
        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
            case KeyEvent.KEYCODE_DPAD_RIGHT /*22*/:
                this.c = 3;
                this.d = 2;
                setKeyProgressIncrement(this.increment);
                break;
        }
        return super.onKeyUp(keyCode, event);
    }

    public void setDuration(int duration) {
        if (duration > 0) {
            this.mDuration = duration;
        } else {
            this.mDuration = 1;
        }
        if (this.mDuration >= 3600000) {
            this.maxMultiple = 30;
            this.increment = getMax() / HttpStatus.SC_INTERNAL_SERVER_ERROR;
        } else if (this.mDuration >= 1800000) {
            this.maxMultiple = 20;
            this.increment = getMax() / HttpStatus.SC_INTERNAL_SERVER_ERROR;
        } else if (this.mDuration >= 600000) {
            this.maxMultiple = 10;
            this.increment = getMax() / 600;
        } else {
            this.maxMultiple = 5;
            this.increment = getMax() / 700;
        }
    }
}
